import { reactive } from 'vue'
import { FormRules } from 'element-plus'
import { Advise, Notice, Staff } from '@/ts/type'

// eslint no-useless-escape: "error"
const expEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/
const expTelephone = /^1[34578]\d{9}$/
const expIdCard = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
const validateEmail = (_: any, value: any, callback: any) => {
  if (expEmail.test(value)) {
    callback()
  }
  callback(new Error('邮箱格式匹配失败，请检查数据'))
}
const validateTelephone = (_: any, value: any, callback: any) => {
  if (expTelephone.test(value)) {
    callback()
  }
  callback(new Error('手机格式匹配失败，请检查数据'))
}
const validateIdCard = (_: any, value: any, callback: any) => {
  if (expIdCard.test(value)) {
    callback()
  }
  callback(new Error('身份证号码匹配失败，请检查数据'))
}

const checkAge = (_: any, value: any, callback: any) => {
  if (!value) {
    return callback(new Error('请输入年龄'))
  }
  if (!Number.isInteger(value)) {
    callback(new Error('请输入正确的年龄'))
  } else if (value < 1) {
    callback(new Error('年龄必须在正确的范围内'))
  } else {
    callback()
  }
}
export const rules = reactive<FormRules>({
  username: [
    { required: true, message: '请输入姓名', trigger: 'blur' },
    { min: 1, message: '请输入正确的姓名', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 6, message: '请输入六位数密码', trigger: 'blur' },
  ],
  title: [
    { required: true, message: '请输入标题', trigger: 'blur' },
    { min: 3, message: '标题过短，请重新输入', trigger: 'blur' },
  ],
  context: [
    { required: true, message: '请输入内容', trigger: 'blur' },
    { min: 6, message: '内容过短，请重新输入', trigger: 'blur' },
  ],
  status: [{ required: true, message: '请选择选项', trigger: 'blur', }],
  reply: [{ required: true, message: '请输入内容', trigger: 'blur' }],
  email: [{ validator: validateEmail, trigger: 'blur' }],
  telephone: [{ validator: validateTelephone, trigger: 'blur' }],
  areaId: [{ required: true, message: '请输入服务区域', trigger: 'blur' }],
  idCard: [{ validator: validateIdCard, trigger: 'blur' }],
  temper: [{ required: true, message: '请输入体温度数', trigger: 'blur' }],
  headache: [{ required: true, message: '请选择选项', trigger: 'blur' }],
  fever: [{ required: true, message: '请选择选项', trigger: 'blur' }],
  goodsName: [{ required: true, message: '请输入物品名称', trigger: 'blur' }],
  typeId: [{ required: true, message: '请选择选项', trigger: 'blur' }],
  number: [{ required: true, message: '请输入物品数量', trigger: 'blur' }],
  specification: [{ required: true, message: '请输入物品规格', trigger: 'blur' }],
  claimNumber: [{ required: true, message: '请输入申请数量', trigger: 'blur' }],
  uname: [{ required: true, message: '请输入患者名字', trigger: 'blur' }],
  age: [{ validator: checkAge, trigger: 'blur' }],
  phone: [{ required: true, message: '请输入患者手机类型', trigger: 'blur' }],
  roomId: [{ required: true, message: '请输入患者房间编号', trigger: 'blur' }],
  address: [
    { required: true, message: '请输入地址', trigger: 'blur' },
    { min: 5, message: '请输入详细地址', trigger: 'blur' },
  ],
})

// ?2023-4-9 23:43:考虑是否使用重置
export const noticeInit: Notice = {
  title: '',
  context: '',
  time: []
}
export const adviseInit: Advise = {
  context: '',
  status: '',
  reply: ''
}

export const staffInit: Staff = {
  email: '',
  telephone: '',
  address: '',
  remark: ''
}

export const threeOptions = [
  {
    value: '同意',
    label: '同意',
  },
  {
    value: '拒绝',
    label: '拒绝',
  },
  {
    value: '未处理',
    label: '未处理',
  },
]

export const twoOptions = [
  {
    value: '同意',
    label: '同意',
  },
  {
    value: '拒绝',
    label: '拒绝',
  }
]